import React, { Component } from 'react'
import PropTypes from 'prop-types';

export class Tabtop extends Component {
  render() {
      const {list,i,changei,removetab}=this.props
    return (
      <div>
          {list.length?list.map((item,index)=>{
            return <button
                key={item.id}
                onClick={()=>{
                    changei(index)
                }}
                className={i===index?'on':""}
            >
                <span>{item.title}</span>
                <b
                    onClick={(e)=>{
                        e.stopPropagation()
                        removetab(item.id)
                    }}
                >✖</b>
            </button>
          }):'暂无数据'}
          
      </div>
    )
  }
}

Tabtop.propTypes = {
    list: PropTypes.array,
    changei:PropTypes.func.isRequired,
    removetab:PropTypes.func.isRequired
};

Tabtop.defaultProps = {
    list: []
};

export default Tabtop